﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Account/Site.master" AutoEventWireup="true" CodeFile="LoaiTin.aspx.cs" Inherits="Administrator_LoaiTin" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <div>
    <asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" 
        Font-Size="0.8em" PathSeparator=" : " style="font-size: small">
        <CurrentNodeStyle ForeColor="#333333" />
        <NodeStyle Font-Bold="True" ForeColor="#284E98" />
        <PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />
        <RootNodeStyle Font-Bold="True" ForeColor="#507CD1" />
    </asp:SiteMapPath>
        <br />
    <asp:Label ID="Label1" runat="server" 
        style="font-size: x-large; font-weight: 700" Text="Quản lý loại tin"></asp:Label>
        <br />
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" BackColor="White" 
        BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
        DataKeyNames="ID" DataSourceID="SqlDataSource1" EnableModelValidation="True" 
        Width="100%">
        <Columns>
            <asp:CommandField DeleteText="Xóa" EditText="Sửa" InsertText="Thêm mới" 
                NewText="Thêm mới" ShowDeleteButton="True" ShowEditButton="True" 
                UpdateText="Cập nhật">
            <ItemStyle Width="30px" />
            </asp:CommandField>
            <asp:BoundField DataField="TieuDe" HeaderText="Tiêu đề" 
                SortExpression="TieuDe" />
        </Columns>
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <RowStyle ForeColor="#000066" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
    </asp:GridView>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" 
        DataSourceID="SqlDataSource2" EnableModelValidation="True" Width="100%" 
        oniteminserted="FormView1_ItemInserted">
        <EditItemTemplate>
            ID:
            <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
            <br />
            Thể loại :
            <asp:DropDownList ID="DropDownList2" runat="server" 
                DataSourceID="SqlDataSource4" DataTextField="TieuDe" DataValueField="ID" 
                SelectedValue='<%# Bind("TheLoai") %>' Width="300px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT * FROM [TheLoai]"></asp:SqlDataSource>
            <br />
            TenLoai:
            <asp:TextBox ID="TenLoaiTextBox" runat="server" Text='<%# Bind("TieuDe") %>' 
                Width="300px" />
            <br />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
        <EmptyDataTemplate>
            Không có dữ liệu (Click tạo mới)<br />
            <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Tạo mới</asp:LinkButton>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            &nbsp;<table class="style1" width="100%">
                <tr>
                    <td>
                        Thể Loại</td>
                    <td>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSource3" DataTextField="TieuDe" DataValueField="ID" 
                            SelectedValue='<%# Bind("TheLoai") %>' Width="200px">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                            SelectCommand="SELECT * FROM [TheLoai]"></asp:SqlDataSource>
                    </td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td width="100px">
                        Tên loại
                    </td>
                    <td>
                        <asp:TextBox ID="TenLoaiTextBox" runat="server" Text='<%# Bind("TieuDe") %>' 
                            Width="300px" />
                    </td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                </tr>
            </table>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ControlToValidate="TenLoaiTextBox" Display="None" 
                ErrorMessage="Tên loại sản phẩm không được rỗng"></asp:RequiredFieldValidator>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" 
                CommandName="Cancel" Text="Cancel" onclick="InsertCancelButton_Click" />
        </InsertItemTemplate>
        <ItemTemplate>
            &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="Tạo mới" />
        </ItemTemplate>
    </asp:FormView>
        <br />
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
        DeleteCommand="DELETE FROM [LoaiTin] WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [LoaiTin] ([TieuDe], [TheLoai]) VALUES (@TieuDe, @TheLoai)" 
        SelectCommand="SELECT * FROM [LoaiTin]" 
        
            UpdateCommand="UPDATE [LoaiTin] SET [TieuDe] = @TieuDe, [TheLoai] = @TheLoai WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="TieuDe" Type="String" />
            <asp:Parameter Name="TheLoai" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="TieuDe" Type="String" />
            <asp:Parameter Name="TheLoai" Type="Int32" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
        DeleteCommand="delete from loaitin  WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [Loaitin] ([TieuDe]) VALUES (@TieuDe)" 
        SelectCommand="SELECT * FROM [Loaitin] " 
        
        
        UpdateCommand="UPDATE [LoaiTin] SET [TieuDe] = @TieuDe WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="TieuDe" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="TieuDe" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
        <br />
    </div>
</asp:Content>

